/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2021-10-12
 * Time: 22:15
 */
class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
}
class Solution {
    TreeNode cur;//遍历二叉树的节点
    public TreeNode increasingBST(TreeNode root) {
        if (root == null){
            return null;
        }

        //保存前驱节点
        TreeNode prev = new TreeNode(0);
        cur = prev;
        inorder(root);
        return prev.right;
    }

    public void inorder(TreeNode root) {
        if (root == null){
            return;
        }
        inorder(root.left);
        cur.right = root;
        root.left = null;
        cur = root;
        inorder(root.right);
    }
}